package com.zhuanyongjin.server;

import java.io.IOException;
import java.io.PrintWriter;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import com.zhuanyongjin.dao.membersDao;
import com.zhuanyongjin.dao.impl.membersDaoImpl;
import com.zhuanyongjin.util.DataTools;
//用户注册
public class memberLogon extends HttpServlet {

	/**
	 * The doGet method of the servlet. <br>
	 *
	 * This method is called when a form has its tag value method equals to get.
	 * 
	 * @param request the request send by the client to the server
	 * @param response the response send by the server to the client
	 * @throws ServletException if an error occurred
	 * @throws IOException if an error occurred
	 */
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		response.setContentType("text/html");
		response.setCharacterEncoding("utf-8");
		PrintWriter out = response.getWriter();
		//获取用户注册时输入的数据
		String mobel=request.getParameter("mobel");
		String name=request.getParameter("name");
		String password=request.getParameter("password");
		String sex="c4d0";
		membersDao members = new membersDaoImpl();
		List list=members.samename(mobel);
		if(list.size()>0)
		{
			out.print("user_exist");
		}
		else{
			boolean b1=members.Logon(DataTools.HexStringhtoString(name),password,mobel,sex);
			if(b1==true){
			    out.print("success");
			}
			else
			{
				out.println("error");
			}
		}
		out.flush();
		out.close();
	}

	/**
	 * The doPost method of the servlet. <br>
	 *
	 * This method is called when a form has its tag value method equals to post.
	 * 
	 * @param request the request send by the client to the server
	 * @param response the response send by the server to the client
	 * @throws ServletException if an error occurred
	 * @throws IOException if an error occurred
	 */
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		doGet(request, response);
	}

}
